package com.meilele.controller.hongdian;

import com.meilele.biz.hongdian.ThiCaseLableBiz;
import com.meilele.biz.hongdian.ThiCaseBiz;
import com.meilele.entity.hongdian.ThiCase;
import com.meilele.entity.hongdian.ThiCaseLable;
import com.meilele.util.hongdian.Constant;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/caseLable")
public class ThiCaseLableController {

    @Resource
    private ThiCaseLableBiz caseLableBiz;
    @Resource
    private ThiCaseBiz caseBiz;

    /**
     * 装修案例首页并包含最新
     * @param model
     * @param pageNum
     * @return
     */
    @RequestMapping("/index")
    public String index(Model model, int pageNum){
        //案例标签集合
        List<ThiCaseLable> caseLableList = caseLableBiz.findAllCaseLable();
        model.addAttribute("caseLableList",caseLableList);

        //案例列表集合
        List<ThiCase> thiCaseList = caseBiz.findAllCase(pageNum);
        model.addAttribute("thiCaseList",thiCaseList);
        int totalCount = caseBiz.findCount();
        double totalPage = totalCount * 1.0 / Constant.PAGE_SIZE;
        totalCount = (int) Math.ceil(totalPage);
        model.addAttribute("totalCount",totalCount);
        model.addAttribute("pageNum",pageNum);

        return "/caseLable/index";
    }

    /**
     * 点击标签进入新的页面
     * @param model
     * @return
     */
    @RequestMapping("/c-1")
    public String image(Model model,int pageNum){
        //案例标签集合
        List<ThiCaseLable> caseLableList = caseLableBiz.findAllCaseLable();
        model.addAttribute("caseLableList",caseLableList);

        List<ThiCase> thiCaseList = caseBiz.findAllLableCase(pageNum);
        model.addAttribute("thiCaseList",thiCaseList);
        int totalCount = caseBiz.findCount();
        double totalPage = totalCount * 1.0 / Constant.PAGE_SIZE;
        totalCount = (int) Math.ceil(totalPage);
        model.addAttribute("totalCount",totalCount);
        model.addAttribute("pageNum",pageNum);

        return "/caseLable/c-1";
    }

    @RequestMapping("/hot")
    public String house(Model model , int pageNum){

        //案例标签集合
        List<ThiCaseLable> caseLableList = caseLableBiz.findAllCaseLable();
        model.addAttribute("caseLableList",caseLableList);

        List<ThiCase> caseDescPeopleList = caseBiz.findAllCaseDescPeople(pageNum);
        model.addAttribute("caseDescPeopleList",caseDescPeopleList);

        long totalCount = caseBiz.findCount();
        model.addAttribute("totalCount",totalCount);
        model.addAttribute("pageNum",pageNum);
        return "/caseLable/hot";
    }

}
